Post

Replies

Boosts

Views

Activity

Reply to How to register background tasks in a pure SwiftUI app
You can register the task inside the init function of the App struct. @main struct MyApp: App { init(){ // Your code } var body: some Scene { WindowGroup { ContentView() } } } Or, to use AppDelegate in a SwiftUI lifecycle app, first create a custom class of App Delegate. class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { return true } } Then use UIApplicationDelegateAdaptor property wrapper to tell SwiftUI to use your AppDelegate class. @main struct MyApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { ContentView() } } }
Jul ’21
Reply to InputAccessoryView with SwiftUI
There's a new API to do this in iOS 15. Note that this is not compatible with previous versions of iOS. You'll also need Xcode 13 beta to build this. See more at https://www.hackingwithswift.com/quick-start/swiftui/how-to-add-a-toolbar-to-the-keyboard struct ContentView: View { @State private var name = "Taylor" var body: some View { TextField("Enter your name", text: $name) .textFieldStyle(.roundedBorder) .toolbar { ToolbarItemGroup(placement: .keyboard) { Button("Click me!") { print("Clicked") } } } } } Alternatively, you can wrap a UITextView inside your SwiftUI view using UIViewRepresentable. You can then gain access to inputAccessoryView.
Jul ’21
Reply to Bug with image picker : When tapping on the album button the camera opens up
You should implement the updateUIViewController method. When the state of your view is changed, this method is called and you are responsible to update the configuration of your view controller to match the new state information. See more at https://developer.apple.com/documentation/swiftui/uiviewcontrollerrepresentable/updateuiviewcontroller(_:context:) func updateUIViewController(_ uiViewController: UIImagePickerController, context: UIViewControllerRepresentableContext<ImagePicker>) {         uiViewController.sourceType = sourceType }
Jul ’21